<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>－超值优惠－拼多多优惠商城</title>
		<meta
			name="viewport"
			content="width=device-width,minimum-scale=1,initial-scale=1"
		/>
		<meta
			name="keywords"
			content="限时特价，品牌专场，精选爆款，拼多多优惠商城"
		/>
		<meta
			name="baidu-site-verification"
			content="tk4VA7ginX"
		/>
		<meta
			name="360-site-verification"
			content="69745aea5bcc669978016bb0f049b47f"
		/>
		<meta
			name="keyword"
			content="优惠券|包邮|特价|超值优惠"
		/>
		<meta
			name="description"
			content="undefined－超值优惠－拼多多优惠商城"
		/>
		<meta
			name="viewport"
			content="initial-scale=1.0, width=device-width"
		/>
		<meta
			http-equiv="Content-Type"
			content="text/html; charset=UTF-8"
		/>
		<meta name="renderer" content="webkit" />
		<meta
			http-equiv="X-UA-Compatible"
			content="IE=edge,chrome=1"
		/>
		<meta
			http-equiv="Cache-Control"
			content="no-cache,no-store,must-revalidate"
		/>
		<meta
			http-equiv="Pragma"
			content="no-cache"
		/>
		<meta http-equiv="Expires" content="0" />
		<meta
			http-equiv="x-dns-prefetch-control"
			content="on"
		/>
		<link
			href="../../css/main.css"
			rel="stylesheet"
		/>
        <link rel="stylesheet" href="../../css/details/main.css">
		<link
			href="../../css/base.css"
			rel="stylesheet"
		/>
		<link
			rel="stylesheet"
			href="../../css/common.css"
		/>

		<link
			rel="stylesheet"
			href="../../css/chunk.css"
		/>
        <script src="../../js/cookie.js"></script>
        <script src="../../js/jquery3.5.1.js"></script>
        <script src="../../js/PromiseAjax.js"></script>
        <script src="../../js/searchFormater.js"></script>
        <style>
            .enlarge{
                position: absolute;
                display: none;
                width: 330px;
                height: 330px;
                background-repeat: no-repeat;
                background-position: 0px 0px;
                background-size: 990px 990px;
                z-index: 1;
                opacity: 1;
            }
            .mask{
                display: none;
                width: 110px;
                height: 110px;
                background-color: rgb(12, 12, 12);
                opacity: 0.5;
                position: absolute;
                top: 0px;
                left: 0px;
            }
        </style>
	</head>
	<body>
		<div id="__next">
			<div class="site-wrapper">
				<div class="search-bar">
					<div class="top-line"></div>
					<div class="content">
						<img
							src="../../images/804f5f88.png.slim.png"
							alt=""
							class="logo-img"
						/>
						<div class="search-bar-input">
							<input
								type="text"
								placeholder="请输入商品名称"
								value=""
							/><span>搜索</span>
						</div>
						<div class="login-wrapper" style="display: flex;">
							<div>欢迎(<span class="myInfo"></span>)</div>
							<div style="margin-left: 20px;"><a href="./userList.html">我的购物车</a></div>
						</div>
					</div>
				</div>
				<div class="site">
					<div class="site">
					</div>
				</div>
				<div class="footer">
					<p>
						Copyright 2015-<!-- -->2021<!-- -->
						pinduoduo.com 版权所有
						(沪ICP备15010535号)
					</p>
					<a target="_blank"
						href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=31010502000392"
						><div class="record-img"></div>
						<span
							>沪公网安备 31010502000392号</span
						></a
					>
				</div>
			</div>
		</div>
        <script>
            let resId = getCookie("id");
            let username = getCookie("username");
            let ulevel = getCookie("ulevel");
            $(".myInfo").html(username);
            // console.log(resId,!resId);
            if (!resId){
                window.location.href = '../../login.html';
            }
            ajax({
                url:'../../php/footer.php'
            }).then(res=>{
                $(".footer").html(res);
            });
        </script>
        <script>
            $(function(){
                let pid = formatSearch(window.location.search).pid;
                getProDetail(pid);
                function getProDetail(pid){
                    ajax({
                        url:'../../php/index/getData.php',
                        method:'post',
                        dataType:'json',
                        data:{
                            opt:'getProDetail',
                            pid
                        }
                    }).then(res=>{
                        let siteEle = document.querySelector(".site .site");
                        renderDetails(siteEle,res)
                    });    
                }
                function renderDetails(ele,dataArr){
                    ele.innerHTML = '' ;
                    dataArr.forEach(item=>{
                        let divEle = document.createElement("div");
                        divEle.className = "goods-detail-wrapper" ;
                        divEle.innerHTML = `
                                <div class="top-wrapper">
                                    <div class="gallery-wrapper">
                                        <div class="big-pic" style="position:relative">
                                            <div class="mask">
                                            </div>
                                            <img
                                                src="../../${item['showImg']}"
                                            />
                                        </div>
                                        <div class="pic-controller">
                                            <div class="left-controller btn">
                                                <img src="../../images/deqqqq.png.slim.png"
                                                />
                                            </div>
                                            <div class="img-wrapper" style="position:relative;">
                                                <img class="curr" src="../../${item['showImg']}" />
                                            </div>
                                            <div class="right-controller btn" >
                                                <img src="../../images/6cb7cf3.png.slim.png"
                                                />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="top-right-wrapper" style="position:relative;">
                                        <div class="enlarge" style="background-image:url(../../${item['showImg']});">
                                        </div>
                                        <div class="title-wrapper">
                                            【${item['pName']}】${item['pDescribe']}
                                        </div>
                                        <div class="price-wrapper">
                                            <div class="base-info">
                                                <div class="price-info">
                                                    <div class="post-coupon-price-text">
                                                        券后价
                                                    </div>
                                                    <div class="post-coupon-price-symbol">
                                                        ¥
                                                    </div>
                                                    <div class="post-coupon-price">
                                                        ${item['price']}
                                                    </div>
                                                    <div class="raw-price-text">
                                                        原价
                                                    </div>
                                                    <div class="raw-price">
                                                        ¥${item['price'] * 1.3 + 5.5 }
                                                    </div>
                                                </div>
                                            </div>
                                            <div
                                                class="info-spliter"
                                            ></div>
                                            <div class="sales-info">
                                                <div class="sales-text">
                                                    销量
                                                </div>
                                                <div class="quantity">
                                                   ${item['salesNum']}
                                                </div>
                                            </div>
                                        </div>
                                        <div class="sku-wrapper">
                                            <div
                                                class="
                                                    quantity-bar
                                                    info-bar
                                                "
                                            >
                                                <div class="prefix-text">
                                                    数量
                                                </div>
                                                <div class="input-quantity">
                                                    <div class="minus">-</div>
                                                    <input
                                                        class="quantity"
                                                        type="text"
                                                        value="1"
                                                    />
                                                    <div class="plus">+</div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="buy-btns">
                                            <div class="buy-with-coupon" myid="${item['id']}">
                                                点击购买
                                            </div>
                                        </div>
                                    </div>
                                </div>` ;
                        let maskEle = divEle.querySelector(".mask");
                        let enlargeEle = divEle.querySelector(".enlarge");
                        let showEle = divEle.querySelector(".big-pic");
                        let reduceEle = divEle.querySelector(".minus");
                        let plusEle = divEle.querySelector(".plus");
                        let numEle = divEle.querySelector(".input-quantity .quantity");
                        let btnEle = divEle.querySelector(".buy-with-coupon");
                        enlarge(showEle,maskEle,enlargeEle);
                        reduceEle.onclick = function (){
                            if( numEle.value > 1 ){
                                numEle.value = parseInt(numEle.value) - 1 ;
                            }
                        }
                        plusEle.onclick = function (){
                            numEle.value = parseInt(numEle.value) + 1 ;
                        }
                        btnEle.onclick = function (){
                            let pid = this.getAttribute("myid");
                            let resId = getCookie("id");
                            let num = $(".input-quantity .quantity").val();
                            // console.log(pid,resId);
                            ajax({
                                url:'../../php/index/operateGood.php',
                                method:'post',
                                dataType:'json',
                                data:{
                                    opt:'buyGoods',
                                    pid,
                                    resId,
                                    num
                                }
                            }).then(res=>{
                                if( res['status'] == 1 ){
                                    alert("购买成功！");
                                    getProDetail(pid);
                                } else {
                                    alert("操作失败，请重新购买！");
                                }
                            });
                        }
                        ele.appendChild(divEle);
                    });
                }
                function enlarge(ele,maskEle,enlargeEle){
                    ele.onmouseenter = function (){
                        maskEle.style.display = "block" ;  
                        enlargeEle.style.display = "block" ;                   
                    }
                    ele.onmouseleave = function (){
                        maskEle.style.display = "none" ;  
                        enlargeEle.style.display = "none" ; 
                    }
                    ele.onmousemove = function (event){
                        let e  = event || window.event ;
                        let maskEleX = parseInt(getComputedStyle(maskEle,"null")['width']); 
                        let maskEleY = parseInt(getComputedStyle(maskEle,"null")['height']); 
                        let x = e.clientX - ele.offsetLeft - maskEleX / 2; 
                        let y = e.clientY - ele.offsetTop - maskEleY / 2 ; 
                        if( x < 0 ){
                            x = 0 ; 
                        }
                        if(x > ele.offsetWidth - maskEleX){
                            x = ele.offsetWidth - maskEleX ;
                        }
                        if( y < 0 ){
                            y = 0 ; 
                        }
                        if(y > ele.offsetHeight - maskEleY){
                            y = ele.offsetHeight - maskEleY ;
                        }
                        let str = getComputedStyle(enlargeEle,'null')['background-size'];
                        let arr = str.split(" ").map(item=>parseInt(item));
                        
                        enlargeEle.style.backgroundPosition = `-${arr[0] * x / ele.offsetWidth}px -${arr[1] * y / ele.offsetHeight}px` ;
                        maskEle.style.top = `${y}px`  ;
                        maskEle.style.left = `${x}px`  ;
                    }
                }
            });
        </script>
	</body>
</html>
